package com.tiantian.novel.rest;

import com.tiantian.novel.model.NovelSummary;
import com.tiantian.novel.service.SinaBlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Sina解析
 *
 * @author wangk21
 * @date 2023/11/26.
 */
@Slf4j
@RequestMapping("/sina")
@RestController
public class SinaController {
    // https://blog.sina.com.cn/s/articlelist_1215172700_10_1.html
    @Autowired
    private SinaBlogService sinaBlogService;

    /**
     * 抓取小说
     *
     * @param url url
     *
     * @return NovelSummary
     * @throws Exception
     */
    @GetMapping("/fetch")
    public NovelSummary fetch(@RequestParam String url,
                              @RequestParam(required = false) String keywords) {
        return sinaBlogService.fetch(url, keywords);
    }
}
